﻿
@using DAL;
@using DataProj.Areas.BackSys.ServiceTools;
@model List<DAL.UserInfo>

@{
    ViewBag.Title = "个人简介";
    Layout = "../Shared/_LayoutBase.cshtml";
    int id = 0;
    string loginType = String.Empty;
    string userName = string.Empty;
    string trueName = string.Empty;
    string phone = string.Empty;
    string idCard = string.Empty;
    string email = string.Empty;
    string address = string.Empty;
    Nullable<System.DateTime> addTime = null;
    Nullable<System.DateTime> updateTime = null;
    int bagNums = 0, complaintNums = 0;
    try
    {
        loginType = MySession.GetSession("loginType");
        bagNums = Convert.ToInt32(MySession.GetSession("bagNums"));
        complaintNums = Convert.ToInt32(MySession.GetSession("complaintNums"));
    }
    catch (Exception)
    {
        Response.Write("<script languge='javascript'>alert('网页出错了');window.parent.location.href='./Login';</script>");
        Response.End();
    }


    switch (loginType)
    {
        case "管理员":
            Manager manager = MySession.GetSession_ManagerInfo("detail");
            id = manager.ID;
            userName = manager.UserName;
            trueName = manager.TrueName;
            phone = manager.Phone;
            addTime = manager.AddTime;
            updateTime = manager.UpdateTime;
            idCard = manager.IDCard;
            break;
        case "快递员":
            Deliveryman deli = MySession.GetSession_DeliverymanInfo("detail");
            id = deli.ID;
            userName = deli.UserName;
            trueName = deli.TrueName;
            phone = deli.Phone;
            addTime = deli.AddTime;
            updateTime = deli.UpdateTime;
            idCard = deli.IDCard;
            break;
        case "用户":
            UserInfo user = MySession.GetSession_UserInfo("detail");
            id = user.ID;
            userName = user.UserName;
            trueName = user.TrueName;
            phone = user.Phone;
            addTime = user.AddTime;
            updateTime = user.UpdateTime;
            idCard = user.IDCard;
            email = user.Email;
            address = user.ContactAddress;
            break;
        default:
            break;
    }

}
<div class="row col-lg-4">

    <section class="panel">
        <header class="panel-heading">
            个人资料
        </header>
        <div class="panel-body center">

            <ul class="p-info ">
                <li>
                    <div class="title">
                        编号
                    </div>
                    <div id="update_ID" class="desk">
                        @id
                    </div>
                </li>
                <li>
                    <div class="title">
                        权限
                    </div>
                    <div class="desk">
                        @loginType
                    </div>
                </li>

                <li>
                    <div class="title">
                        账户昵称
                    </div>
                    <div class="desk">
                        @userName
                    </div>

                </li>
                <li>
                    <div class="title">
                        真实姓名
                    </div>
                    <div class="desk">
                        @trueName
                    </div>

                </li>
                <li>
                    <div class="title">
                        身份证号
                    </div>
                    <div class="desk">
                        @idCard
                    </div>

                </li>
                <li>
                    <div class="title">
                        手机号
                    </div>
                    <div class="desk">
                        @phone
                    </div>

                </li>
                <li>
                    <div class="title">
                        注册时间
                    </div>
                    <div class="desk">
                        @addTime.ToString()
                    </div>

                </li>
                <li>
                    <div class="title">
                        更新时间
                    </div>
                    <div class="desk">
                        @updateTime.ToString()
                    </div>

                </li>
                @if (loginType.Equals("用户"))
                {
                    <li>
                        <div class="title">
                            邮箱
                        </div>
                        <div class="desk">
                            @email
                        </div>

                    </li>
                    <li>
                        <div class="title">
                            联系地址
                        </div>
                        <div class="desk">
                            @address
                        </div>

                    </li>
                }
                <li>

                    <div class="form-group">
                        <div class="col-sm-4"></div>

                        <button id="update_btn" class="btn btn-info" type="button" data-toggle="modal" data-target="#updateModal">修改</button>

                    </div>
                </li>

            </ul>



        </div>
    </section>
    <section class="panel">
        <header class="panel-heading">
            统计
        </header>
        <div class="panel-body center">

            <ul class="p-info ">
                <li>
                    <div class="title">
                        投诉总数
                    </div>
                    <div class="desk">
                        @complaintNums
                    </div>
                </li>
                <li>
                    <div class="title">
                        已处理总数
                    </div>
                    <div class="desk">
                        @complaintNums
                    </div>
                </li>
                <li>
                    <div class="title">
                        未处理投诉总数
                    </div>
                    <div class="desk">
                        @complaintNums
                    </div>
                </li>
                <li>
                    <div class="title">
                        快递总数
                    </div>
                    <div class="desk">
                        @bagNums
                    </div>
                </li>

            </ul>
        </div>
    </section>

    <input id='act' value='keep' style="visibility: hidden">


    <!-- 模态框示例（Modal） -->
    <form method="post" action="" class="form-horizontal" role="form" id="form_data" onsubmit="return check_form()" style="margin: 20px;">
        <div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" onclick="trigger_stay()" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title" id="myModalLabel">
                            用户详细信息
                        </h4>
                    </div>

                    <div class="modal-body">
                        <div class="form-group">
                            <label for="lastname" class="col-sm-3 control-label">账户昵称</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="update_UserName" name="update_UserName" value="@userName">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="lastname" class="col-sm-3 control-label">真实姓名</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="update_TrueName" name="update_sendDate" value="@trueName">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="lastname" class="col-sm-3 control-label">手机号</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="update_Phone" name="update_getName" value="@phone">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="remark" class="col-sm-3 control-label">身份证号</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="update_IDCard" name="update_IDCard" value="@idCard">
                            </div>
                        </div>
                        @if (loginType.Equals("用户"))
                        {
                            <div class="form-group">
                                <label for="remark" class="col-sm-3 control-label">邮箱</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="update_Email" name="update_getPhone" value="@email">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="remark" class="col-sm-3 control-label">联系地址</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="update_Address" name="update_getAddress" value="@address">

                                </div>
                            </div>
                        }
                        else
                        {
                            <div class="form-group">
                                <label for="remark" class="col-sm-3 control-label">邮箱</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="update_Email" name="update_getPhone" value="" hidden="hidden">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="remark" class="col-sm-3 control-label">联系地址</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="update_Address" name="update_getAddress" value="" hidden="hidden">

                                </div>
                            </div>
                        }





                    </div>
                    <div class="modal-footer">
                        <button onclick="trigger_stay()" type="button" class="btn btn-default" data-dismiss="modal">
                            关闭
                        </button>
                        <button type="button" onclick="return  check_form()" class="btn btn-primary">
                            提交
                        </button><span id="tip"> </span>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>
    </form>
    <!--body wrapper end-->
    <!--footer section start-->

    <!--footer section end-->


</div>


@section JavascriptLink{
    <script src="../../../../Content/backSys/js/jquery.signalR-2.4.3.min.js"></script>
    <script src="/signalr/hubs" type="text/javascript"></script>

}
@section Javascript{

    <script>
        $(function () {
            //引用服务端的集线器代理类
            var chat = $.connection.ChatHub;
            //定义服务器端调用的客户端SendMessage方法来显示新消息
            chat.client.Pull = function (message) {
                ShowMessage(message);
            };

            //开始连接服务器
            $.connection.hub.start().done(function () {
                chat.server.init();
                callReady();
            });
        });
        // 提交表单
        function check_form() {

            id = $.trim($('#update_ID')[0].innerText);
            if (!id) {
                alert('ID不能为空！');
                trigger_stay();
                return false;
            }
            $('#act').val('update');
            //var act = $.trim($('#act').val());
            //var form_data = $('#form_data').serialize();
            var sendData = [];
            var sendUrl = '';
            sendUrl = '@Url.Action("Update","Welcome")';
            sendData = {
                'ID': id,
                'UserName': $('#update_UserName').val(),
                'UserPass': $('#update_UserPass').val(),
                'TrueName': $('#update_TrueName').val(),
                'Phone': $('#update_Phone').val(),
                'IDCard': $('#update_IDCard').val(),
                'Email': $('#update_Email').val(),
                'Address': $('#update_Address').val()
            };
            // 异步提交数据到action/GetBagItemByID页面
            $.ajax(
                {
                    url: sendUrl,
                    data: sendData,
                    type: 'POST',
                    dataType: 'json',
                    beforeSend: function () {
                        $("#tip").html("<span style='color:blue'>正在处理...</span>");
                        return true;
                    },
                    success: function (data) {
                        if (data > 0) {
                            $("#tip").html("<span style='color:blueviolet'>" + act + "成功！</span>");
                            // document.location.href='system_notice.php'
                            $('#updateModal').modal('hide')
                            commonUtil.message("更新成功", "结果已更新到数据库", "success");
                            location.reload();
                        }
                        else {
                            $("#tip").html("<span style='color:red'>失败，请重试</span>");
                            commonUtil.message("更新错误", "网络错误", "danger");
                            $('#updateModal').modal('hide');
                        }
                    },
                    error: function () {
                        alert('请求出错');
                    },
                    complete: function () {
                        $('#acting_tips').hide();
                    }
                });

            return false;
        }

    </script>
}